package com.hnkywl.sts.util;

import com.hnkywl.sts.dao.sys.GgDao;
import com.hnkywl.sts.entity.cggl.Cgd;
import com.hnkywl.sts.entity.cggl.Cgdmx;
import com.hnkywl.sts.entity.sys.Gg;
import com.hnkywl.sts.entity.xsgl.Xsd;
import com.hnkywl.sts.entity.xsgl.Xsmx;
import net.ruixin.utils.CollectionUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * json拼成
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-3-2
 * Time: 下午3:46
 * To change this template use File | Settings | File Templates.
 */
public class JsonUtils {
    private GgDao ggDao;

    /**
     * 拼接质押方库存信息查询json
     *
     * @param zyfName
     * @param zyfPm
     * @param zyfCz
     * @param zyfGgxh
     * @param zyfCk
     * @param zyfCd
     * @return
     */
    public static String createhqmxListJson(String zyfName, String zyfPm, String zyfCz, String zyfGgxh, String zyfCk, String zyfCd) {
        StringBuffer sb = new StringBuffer();
//        sb.append("");
        sb.append("{\"buyerCompany\":\"").append(zyfName).append("\",");
        sb.append("\"name\":\"").append(zyfPm.isEmpty() ? " " : zyfPm).append("\",");
        sb.append("\"quality\":\"").append(zyfCz.isEmpty() ? " " : zyfCz).append("\",");
        sb.append("\"standard\":\"").append(zyfGgxh.isEmpty() ? " " : zyfGgxh).append("\",");
        sb.append("\"field\":\"").append(zyfCd.isEmpty() ? " " : zyfCd).append("\",");
        sb.append("\"warehouse\":\"").append(zyfCk).append("\"");
        sb.append("}");
        String json = sb.toString();
        return json;
    }
    public static String createhqmx1ListJson(String xhtbm) {
        StringBuffer sb = new StringBuffer();
//        sb.append("");
        sb.append("{\"orderItemNum \":\"").append(xhtbm).append("\"");
  /*      sb.append("\"name\":\"").append(zyfPm.isEmpty() ? " " : zyfPm).append("\",");
        sb.append("\"quality\":\"").append(zyfCz.isEmpty() ? " " : zyfCz).append("\",");
        sb.append("\"standard\":\"").append(zyfGgxh.isEmpty() ? " " : zyfGgxh).append("\",");
        sb.append("\"field\":\"").append(zyfCd.isEmpty() ? " " : zyfCd).append("\",");
        sb.append("\"warehouse\":\"").append(zyfCk).append("\"");*/
        sb.append("}");
        String json = sb.toString();
        return json;
    }





    public static String createZyfKcxxListJson(String zyfName, String zyfPm, String zyfCz, String zyfGgxh, String zyfCk, String zyfCd) {
        StringBuffer sb = new StringBuffer();
//        sb.append("");
        sb.append("{\"buyerCompany\":\"").append(zyfName).append("\",");
        sb.append("\"name\":\"").append(zyfPm.isEmpty() ? " " : zyfPm).append("\",");
        sb.append("\"quality\":\"").append(zyfCz.isEmpty() ? " " : zyfCz).append("\",");
        sb.append("\"standard\":\"").append(zyfGgxh.isEmpty() ? " " : zyfGgxh).append("\",");
        sb.append("\"field\":\"").append(zyfCd.isEmpty() ? " " : zyfCd).append("\",");
        sb.append("\"warehouse\":\"").append(zyfCk).append("\"");
        sb.append("}");
        String json = sb.toString();
        return json;
    }
    /**
     * 模拟测试查询质押方库存信息
     *
     * @return
     */
    public static String createZyfKcxxListResultJson() {
        StringBuffer sb = new StringBuffer();
        sb.append("[");
        sb.append("{\"stander_name\":\"").append("螺纹钢").append("\",");
        sb.append("\"material\":\"").append("HRB400E").append("\",");
        sb.append("\"spec\":\"").append("32").append("\",");
        sb.append("\"brand\":\"").append("宣钢").append("\",");
        sb.append("\"warehouse\":\"").append("成都达海仓库").append("\",");
        sb.append("\"resource_serial_number_1\":\"").append("KE120320101").append("\",");
        sb.append("\"numberUnit\":\"").append("件").append("\",");
        sb.append("\"measure_count\":\"").append(50).append("\",");
        sb.append("\"weightUnit \":\"").append("吨").append("\",");
        sb.append("\"total_measure\":\"").append(1000).append("\"},");
        sb = sb.deleteCharAt(sb.length() - 1);
        sb.append("]");
        String json = sb.toString();
        return json;
    }

    public static String createZyfKcxxListResultJson1() {
        StringBuffer sb = new StringBuffer();
        sb.append("[");
        sb.append("{\"wzgg.id\":\"").append(825032).append("\",");
        sb.append("\"wzgg.name\":\"").append("螺纹钢").append("\",");
        sb.append("\"wzgg.ggxh\":\"").append("14*12000").append("\",");
        sb.append("\"wzgg.dw\":\"").append("t").append("\",");
        sb.append("\"wzgg.cz\":\"").append("HRB400E").append("\",");
        sb.append("\"spec\":\"").append("32").append("\",");
        sb.append("\"cd.z\":\"").append("宣钢").append("\",");
        sb.append("\"xsxt_xsdh\":\"").append("KE120320101").append("\",");
        sb.append("\"hsj\":\"").append(50).append("\",");
        sb.append("\"bhsj\":\"").append(50).append("\",");
        sb.append("\"sbjs\":\"").append(50).append("\",");
        sb.append("\"jzfs.z\":\"").append("吨").append("\",");
        sb.append("\"sbsl\":\"").append(1000).append("\"},");
        sb = sb.deleteCharAt(sb.length() - 1);
        sb.append("]");
        String json = sb.toString();
        return json;
    }

    /**
     * 模拟测试查询采购合同明细信息
     *
     * @return
     */
    public static String createHqmxListResultJson() {
        StringBuffer sb = new StringBuffer();
        sb.append("[");
        sb.append("{\"wzgg_code\":\"").append("22222").append("\",");
        sb.append("\"wzgg_name\":\"").append("螺纹钢").append("\",");
        sb.append("\"wzgg_ggxh\":\"").append("32").append("\",");
        sb.append("\"wzgg_cz\":\"").append("HRB400E").append("\",");
        sb.append("\"wzgg_dw\":\"").append("吨").append("\",");
        sb.append("\"cd_z\":\"").append("攀钢").append("\",");
        sb.append("\"sbjs\":\"").append(50).append("\",");
        sb.append("\"sbsl\":\"").append(50).append("\",");
        sb.append("\"jzfs_z \":\"").append("吨").append("\",");
        sb.append("\"hsj\":\"").append(1000).append("\"},");
        sb.append("\"bhsj\":\"").append(1000).append("\"},");
        sb.append("\"hsje\":\"").append(1000).append("\"},");
        sb.append("\"xsxt_xsdh\":\"").append("88xss").append("\"},");
        sb.append("\"spec\":\"").append("34").append("\"},");
        sb = sb.deleteCharAt(sb.length() - 1);
        sb.append("]");
        String json = sb.toString();
        return json;
    }

    /**
     * 质押
     *
     * @return
     */
    public static String createCgdZyJson(Cgd cgd) {
        StringBuffer sb = new StringBuffer();
        sb.append("{\"scontractBillcode\":\"").append(cgd.getCgdh()).append("\",");
        sb.append("\"billBillcode\":\"").append(cgd.getCgdh()).append("\",");
        sb.append("\"buyerCompany\":\"").append(cgd.getGys().getQc()).append("\",");
        sb.append("\"reportCompany\":\"").append(cgd.getSbgs().getQc()).append("\",");
        sb.append("\"goodsNum\":\":goodsNum\",");
        sb.append("\"goodsWeight\":\":goodsWeight\",");
        sb.append("\"scontractPumode\":\"").append("transfer").append("\",");
        sb.append("\"billType\":\"lading\",");
        sb.append("\"status\":\"0\",");
        sb.append("\"transferSign\":\"1\",");
        sb.append("\"materialType\":\"1\",");
        sb.append("\"memberCode\":\"").append(cgd.getSbgs().getBm()).append("\",\"saleBillCodeViewVoList\":[");
        Integer js = 0;
        Double sl = 0.0;
        for (Cgdmx cgdmx : cgd.getCgdmxList()) {
            sb.append("{\"name\":\"").append(cgdmx.getGg().getName()).append("\",");
            sb.append("\"quality\":\"").append(cgdmx.getGg().getCz()).append("\",");
            sb.append("\"standard\":\"").append(cgdmx.getGg().getGgxh()).append("\",");
            sb.append("\"standardModel\":\"").append(cgdmx.getGg().getGgxh()).append("\",");
            sb.append("\"field\":\"").append(cgdmx.getCd().getZ()).append("\",");
            sb.append("\"warehouse\":\"").append(cgd.getDzck().getMc()).append("\",");
          //  sb.append("\"resource_serial_number_1\":\"").append(cgdmx.getResource_serial_number_1()).append("\",");
            sb.append("\"numberUnit\":\"").append("件").append("\",");
            sb.append("\"number\":\"").append(cgdmx.getJs() == null ? 1 : cgdmx.getJs()).append("\",");
            sb.append("\"weightUnit \":\"").append(cgdmx.getGg().getDw()).append("\",");
            sb.append("\"weight\":\"").append(cgdmx.getSbsl()).append("\"},");
            js += cgdmx.getJs() == null ? 1 : cgdmx.getJs();
            sl += cgdmx.getSbsl();
        }
        sb = sb.deleteCharAt(sb.length() - 1);
        sb.append("]}");
        String json = sb.toString().replaceAll(":goodsNum", js.toString());
        json = json.replaceAll(":goodsWeight", sl.toString());
        return json;
    }
    @Autowired
    public void setGgDao(GgDao ggDao) {
        this.ggDao = ggDao;
    }
}
